package com.hunk.core.auth.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.hunk.core.entity.UUIDEntity;

@Entity
@Table(name="SYS_USER")
public class User extends UUIDEntity {

	private static final long serialVersionUID = 2501743965571432199L;
	// 字段非空且唯一, 用于提醒Entity使用者及生成DDL.
	@Size (min=6, max=20, message="用户名长度只能在6-20之间")  
	@Column(name = "username", nullable = false, unique = true)
	private String username;
	@JsonIgnore
	@Size (min=6, max=20, message="密码长度只能在6-20之间")
	private String password;
	private boolean enabled;
	@Size (min=6, max=20, message="用户名长度只能在6-20之间")  
	private String realname;
	@Pattern (regexp="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}", message="邮件格式错误") 
	private String email;
	private String phone;
	private String address;
	private String mobile;
	private String remark;
    
	public User() {
	}

	public User(String username, String password) {
		this.username = username;
		this.password = password;
	}

    public User(String username, String password, String realname) {
		super();
		this.username = username;
		this.password = password;
		this.realname = realname;
	}

	public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    @JsonIgnore
    public String getPassword() {
        return password;
    }
    @JsonProperty
    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Override
	public String toString() {
		return "User [id=" + getId() + ", username=" + username + ", password="
				+ password + ", enabled=" + enabled + ", realname=" + realname
				+ ", email=" + email + ", phone=" + phone + ", address="
				+ address + ", mobile=" + mobile + ", remark=" + remark + "]";
	}

}
